import numpy as np
from sklearn.metrics import roc_auc_score

# 预测价格
predicted_prices = np.array([15175.073269317887, 4866.106270553486, 3531.77300660236, 13328.2607610938, 14873.979838401166])
# 实际价格
actual_prices = np.array([15200.0, 4200.0, 4000.0, 13300.0, 13100.0])

# 通过比较预测价格和实际价格来生成二分类的标签
y_true = np.where(predicted_prices >= actual_prices, 1, 0)
y_scores = predicted_prices  # 使用预测价格作为预测概率（在这种简单转换下）

# 计算ROC - AUC
roc_auc = roc_auc_score(y_true, y_scores)
print("ROC - AUC:", roc_auc)

import numpy as np
import matplotlib.pyplot as plt
from sklearn import metrics

# 预测价格
predicted_prices = np.array([15175.073269317887, 4866.106270553486, 3531.77300660236, 13328.2607610938, 14873.979838401166])
# 实际价格
actual_prices = np.array([15200.0, 4200.0, 4000.0, 13300.0, 13100.0])

y_true = np.where(predicted_prices >= actual_prices, 1, 0)
y_scores = predicted_prices

fpr, tpr, thresholds = metrics.roc_curve(y_true, y_scores)
roc_auc = metrics.auc(fpr, tpr)

plt.plot(fpr, tpr, color='darkorange', lw=2, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic example')
plt.legend(loc="lower right")
plt.show()